import struct
import numpy as np
import pandas as pd

class ICRIteration:
    '''
      mu_stars
      sigma_stars
      njstar
      alpha
    '''
    def __init__(self, f, ncol, N):
        self.iternum = struct.unpack('d', f.read(8))[0]
        self.mu_stars = np.array(struct.unpack('d'*int(ncol*N),f.read(int(8*N*ncol)))).reshape(int(N),int(ncol))
        self.sigma_stars = np.array(struct.unpack('d'*int(N*ncol**2),f.read(int(8*N*ncol**2)))).reshape(int(N),ncol,ncol)
        self.njstar = np.array(struct.unpack('d'*int(N),f.read(int(8*N))))
        self.alpha = np.array(struct.unpack('d',f.read(int(8)))[0])
    def help(self):
        print "njstar, alpha, sigma_stars, mu_stars"



f= open("testdata.out", "rb")

#x = struct.unpack('d'*(len(content)/8), content)

niter = struct.unpack('d',f.read(8))[0]
N = struct.unpack('d', f.read(8))[0]
ncol = struct.unpack('d', f.read(8))[0]
done = False
iterations = []
while(done == False):
   try:
       iterations.append(ICRIteration(f,ncol,N))
   except:
       done=True
